﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace ERPTemplate.Template.MultiTable
{
    public partial class MultiTableDetailEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (ValidateParams() == false)
            {
                return;
            }

            if (!IsPostBack)
            {
                BindData();
            }
        }
        /// <summary>
        /// 验证参数
        /// </summary>
        /// <returns></returns>
        protected bool ValidateParams()
        {
            bool result = true;
            result &= ((Request["type"] == "add") || (Request["type"] == "edit" && Request["recid"] != null));
            return result;
        }
        /// <summary>
        /// 绑定数据
        /// </summary>
        protected void BindData()
        {
            if (Request["type"] == "add")
            {
                RuleButton_Modify.Text = "增加";
                RuleCode.Table.RecordSetPermissions u = new RuleCode.Table.RecordSetPermissions();
                RuleGroup1.IsInsert = true;
                RuleGroup1.SetTableFieldGroup(u, "");
            }
            else if (Request["type"] == "edit")
            {
                RuleButton_Modify.Text = "修改";
                RuleCode.Table.RecordSetPermissions u = RuleCode.Table.RecordSetPermissions.Find("RECID=" + Request["recid"]);
                RuleGroup1.SetTableFieldGroup(u, "");

            }
        }


        protected void Button_modify_Click(object sender, EventArgs e)
        {
            if (Request["type"] == "add")
            {
                RuleCode.Table.RecordSetPermissions u = new RuleCode.Table.RecordSetPermissions();
                u.New();
                RuleGroup1.GetTableFieldGroupValue(u);
                u.Modify();
            }
            else if (Request["type"] == "edit")
            {
                RuleCode.Table.RecordSetPermissions u = RuleCode.Table.RecordSetPermissions.Find("RECID=" + Request["recid"]);
                RuleGroup1.GetTableFieldGroupValue(u);
                u.Modify();

            }
            ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "refresh",
                "<script type='text/javascript'>refreshParent();</script>", false);

        }
    }
}
